package com.lancoo.znbkxx.teacher.aibkTestCoach.paperToPreview

import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ChildPre
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.PaperPreviewInfor

object PreviewInforIndexHelp {

    fun getChildListBean(
            paperPreviewInfor: PaperPreviewInfor,
            index_A: Int,
            index_B: Int,
            index_C: Int
    ): ChildPre {
        return paperPreviewInfor.TypeList[index_A].QuesDetailList[index_B].ChildList[index_C]
    }

    /*
    * 获取试题位置index
    * */
    fun SortIndex_return_ParentVpPosition(paperPreviewInfor: PaperPreviewInfor, sortIndex: String): Int {
        var parentPosition = -1
        var typeListSize = paperPreviewInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var quesListSize = paperPreviewInfor.TypeList[a].QuesList.size
            for (b in 0 until quesListSize) {
                parentPosition += 1
                var SortIndexListSize = paperPreviewInfor.TypeList[a].QuesList[b].SortIndexList.size
                for (c in 0 until SortIndexListSize) {
                    var SortIndex = paperPreviewInfor.TypeList[a].QuesList[b].SortIndexList[c].SortIndex
                    if (SortIndex == sortIndex) {
                        break@outLoop
                    }
                }
            }
        }
        return parentPosition
    }

    fun SortIndex_return_IndexA(paperPreviewInfor: PaperPreviewInfor, sortIndex: String): Int {
        var index_A = 0
        var typeListSize = paperPreviewInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var quesListSize = paperPreviewInfor.TypeList[a].QuesList.size
            for (b in 0 until quesListSize) {
                val childListSize = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList.size
                for (c in 0 until childListSize) {
                    val itemListSize = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList.size
                    for (d in 0 until itemListSize) {
                        var itemSortIndex = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList[d].ItemSortIndex
                        if (itemSortIndex.contains(sortIndex)) {
                            index_A = a
                            break@outLoop
                        }
                    }
                }
            }
        }
        return index_A
    }

    fun SortIndex_return_IndexB(paperPreviewInfor: PaperPreviewInfor, sortIndex: String): Int {
        var index_B = 0
        var typeListSize = paperPreviewInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var quesListSize = paperPreviewInfor.TypeList[a].QuesList.size
            for (b in 0 until quesListSize) {
                val childListSize = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList.size
                for (c in 0 until childListSize) {
                    val itemListSize = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList.size
                    for (d in 0 until itemListSize) {
                        var itemSortIndex = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList[d].ItemSortIndex
                        if (itemSortIndex.contains(sortIndex)) {
                            index_B = b
                            break@outLoop
                        }
                    }
                }
            }
        }
        return index_B
    }

    fun SortIndex_return_IndexC(paperPreviewInfor: PaperPreviewInfor, sortIndex: String): Int {
        var index_C = 0
        var typeListSize = paperPreviewInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var quesListSize = paperPreviewInfor.TypeList[a].QuesList.size
            for (b in 0 until quesListSize) {
                val childListSize = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList.size
                for (c in 0 until childListSize) {
                    val itemListSize = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList.size
                    for (d in 0 until itemListSize) {
                        var itemSortIndex = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList[d].ItemSortIndex
                        if (itemSortIndex.contains(sortIndex)) {
                            index_C = c
                            break@outLoop
                        }
                    }
                }
            }
        }
        return index_C
    }

    fun SortIndex_return_IndexD(paperPreviewInfor: PaperPreviewInfor, sortIndex: String): Int {
        var index_D = 0
        var typeListSize = paperPreviewInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var quesListSize = paperPreviewInfor.TypeList[a].QuesList.size
            for (b in 0 until quesListSize) {
                val childListSize = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList.size
                for (c in 0 until childListSize) {
                    val itemListSize = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList.size
                    for (d in 0 until itemListSize) {
                        var itemSortIndex = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList[c].ItemList[d].ItemSortIndex
                        if (itemSortIndex.contains(sortIndex)) {
                            index_D = d
                            break@outLoop
                        }
                    }
                }
            }
        }
        return index_D
    }

    /*
    * 获取题型序号从0开始
    * */
    fun QuesPosition_return_TypeListPosition(paperPreviewInfor: PaperPreviewInfor, position: Int): Int {
        var positionX = -1
        var TypeListPosition = 0
        var typeListSize = paperPreviewInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var QuesListSize = paperPreviewInfor.TypeList[a].QuesList.size
            for (b in 0 until QuesListSize) {
                positionX += 1
                if (position == positionX) {
                    TypeListPosition = a
                    break@outLoop
                }
            }
        }
        return TypeListPosition
    }

    /*
* 获取题型序号从0开始
* */
    fun QuesPosition_return_QuesListPosition(paperPreviewInfor: PaperPreviewInfor, position: Int): Int {
        var positionX = -1
        var QuesListPosition = 0
        var typeListSize = paperPreviewInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var QuesListSize = paperPreviewInfor.TypeList[a].QuesList.size
            for (b in 0 until QuesListSize) {
                positionX += 1
                if (position == positionX) {
                    QuesListPosition = b
                    break@outLoop
                }
            }
        }
        return QuesListPosition
    }

    //通过小题序号 -> ItemSortIndex
    fun ChildVpIndex_return_ItemSortIndex(paperPreviewInfor: PaperPreviewInfor, index_A: Int, index_B: Int, childVpIndex: Int): String {
        var itemSortIndex = ""
        var childVpIndexA = -1
        var childListSize = paperPreviewInfor.TypeList[index_A].QuesDetailList[index_B].ChildList.size
        outLoop@ for (c in 0 until childListSize) {
            var itemListSize = getChildListBean(paperPreviewInfor, index_A, index_B, c).ItemList.size
            for (d in 0 until itemListSize) {
                childVpIndexA += 1
                if (childVpIndexA == childVpIndex) {
                    val AAA = index_A
                    val BBB = index_B
                    val CCC = c
                    val DDD = d
                    itemSortIndex = getChildListBean(paperPreviewInfor, index_A, index_B, c).ItemList[d].ItemSortIndex
                    break@outLoop
                }
            }
        }
        return itemSortIndex
    }

    fun ItemSortIndex_return_ChildVpIndex(paperPreviewInfor: PaperPreviewInfor, itemsortIndex: String): Int {
        var childVpIndex = -1
        val typeListSize = paperPreviewInfor.TypeList.size
        outLoop@ for (a in 0 until typeListSize) {
            var quesDetailListSize = paperPreviewInfor.TypeList[a].QuesDetailList.size
            for (b in 0 until quesDetailListSize) {
                childVpIndex = -1
                var childListSize = paperPreviewInfor.TypeList[a].QuesDetailList[b].ChildList.size
                for (c in 0 until childListSize) {
                    var itemListSize = getChildListBean(paperPreviewInfor, a, b, c).ItemList.size
                    for (d in 0 until itemListSize) {
                        childVpIndex += 1
                        val itemSortIndexA = getChildListBean(paperPreviewInfor, a, b, c).ItemList[d].ItemSortIndex
                        if (itemSortIndexA.contains(itemsortIndex)) {
                            break@outLoop
                        }
                    }
                }
            }
        }
        return childVpIndex
    }

}